package com.xiaoshuidi.cloud.module.rooms.valid;

import com.xiaoshuidi.cloud.module.rooms.enums.EquipmentOwn;
import com.xiaoshuidi.cloud.module.rooms.enums.EquipmentPositionType;
import com.xiaoshuidi.cloud.module.rooms.utils.EnumUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 资产导入校验父类
 *
 * @Author Summer
 * @date 2023/10/12
 */
public abstract class AbstractEquipmentExcelImportValid<T> {
    public boolean valid(T t, Map<String, String> errorMap) throws Exception {
        return true;
    }

    public boolean validEquiptmentImportItem(String fieldName, Object fieldValue, Map<String, String> errorMap) throws Exception {
        //位置类别
        if (fieldName.equals("positionTypeName")) {
            String toward = (String) fieldValue;
            if (!toward.equals(EquipmentPositionType.ROOM_HOUSE.getName())) {
                errorMap.put("positionTypeName", "位置类别输入有误！");
                return false;
            }
        }

        //位置类别
        if (fieldName.equals("own")) {
            String toward = (String) fieldValue;
            if (StringUtils.isNotEmpty(toward) && !EnumUtil.isInclude(EquipmentOwn.class, "getName", toward)) {
                errorMap.put("own", "所属方输入有误！");
                return false;
            }
        }

        return true;
    }


}
